class Axis < ActiveRecord::Base
  has_many :axis_values, :order => 'name asc', :dependent => :destroy
	validates_presence_of :name

  named_scope :prioritized, :order => 'position asc'

  class << self
    def legend
      prioritized.collect { |a| a.name.downcase }.join(".")
    end
  end

  def priority
    result = 0
    upto = Axis.all.size - (position - 1)
    1.upto(upto) do |i|
      if i == 1
        result = 1
        next
      end
      result = result * 2
    end
    return result
  end
  
end
